home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Add-Ons / After Dark / Joe Judge / Fractal Popcorn ƒ / module.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-24  |  7.3 KB  |  259 lines  |  [TEXT/KAHL]

  1.  
  2.  
  3. #include "GraphicsModule_Types.h"
  4. #include "Sounds.h"
  5. #include <utils.h>
  6. #include <math.h>
  7.  
  8.  
  9. // these are the functs that need defined ...
  10. OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params);
  11. OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  12. OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  13. OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  14. OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
  15. // these must be defined also
  16. OSErr DoSelected(RgnHandle blankRgn, short message, GMParamBlockPtr params);
  17. OSErr DoAboutBox(RgnHandle blankRgn, short message, GMParamBlockPtr params);
  18.  
  19.  
  20. int errno;
  21. short gTheScreen;
  22.  
  23. double gTop, gLeft, gEdge;
  24. double gIncrement, gScale, gX0, gY0;
  25.  
  26. short gDeltaX, gDeltaY;
  27. //long temp[10];
  28.  
  29.  
  30. #define METHOD    (params->controlValues[0])
  31. #define H_VALUE ( (params->controlValues[1] / 1000.00) > 0 ? \
  32.     (params->controlValues[1] / 1000.00) : 0.001)
  33.     
  34. #define ZOOM    (params->controlValues[2] * 2)
  35. short gAmount;
  36. double gHvalue;
  37. short gZoom;
  38. short gMethod;
  39.  
  40. RGBColor gColor1, gColor2;
  41.  
  42. #define H 0.050        
  43.  
  44.  
  45. //////////////////////////////////////////////////////////////////////////////////////
  46. // this is the first funct called by AD ... we need to allocate and initialize here
  47. OSErr
  48. DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params) {
  49.     
  50.     gDeltaX = gDeltaY = 1;
  51.  
  52.     PickBrightRGB( &gColor1 );
  53.     PickBrightRGB( &gColor2 );
  54.     
  55.     // last things to do 
  56.     gMethod = METHOD;    // how to do color changes
  57.     gAmount = 55;        // was: AMOUNT;
  58.     gZoom = ZOOM;
  59.     gHvalue = H_VALUE;
  60.     gTheScreen = 0;                        // which monitor to run on
  61.     
  62.     return noErr;
  63. }
  64.  
  65. //////////////////////////////////////////////////////////////////////////////////////
  66. // the screen saver has been awakened! time to ditch the storage and wave goodbye
  67. OSErr 
  68. DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) {
  69.  
  70.     return noErr;
  71. }
  72.  
  73.  
  74.  
  75. //////////////////////////////////////////////////////////////////////////////////////
  76. // make the screen go black
  77. OSErr
  78. DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) {
  79.  
  80.     // darken the screen ...
  81.     FillRgn(blankRgn, params->qdGlobalsCopy->qdBlack);
  82.     return noErr;
  83.  
  84. }
  85.  
  86. //////////////////////////////////////////////////////////////////////////////////////
  87. // this is the workhorse routine. It does the continual screen work to make
  88. // this screen saver what it is.
  89. OSErr 
  90. DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) 
  91. {
  92. short j, k, n;
  93. double    x, y, xx, yy;
  94. void plot( double x, double y);
  95. short width, height, windowEdge;
  96. RGBColor rgbTheColor;
  97.  
  98.  
  99.     // definitely needed :) ... since the PickxxxRGB() colors are useless
  100.     // when we !HasColorQD()
  101.     ForeColor( whiteColor);
  102.     BackColor( blackColor);
  103.     
  104. // if we're in DEMO mode ... folks like to poke the controls ... 
  105. // so we *have* to respond to that desire to muck about with things
  106. //
  107. // has the color-change-menu changed ??
  108. //        or
  109. // has the AMOUNT (step) slider changed ?
  110.     if ((METHOD != gMethod) ||
  111.             (H_VALUE != gHvalue) ||
  112.                 (ZOOM != gZoom) ) {
  113.         
  114.         // reset values and clear the screen
  115.         gDeltaX = gDeltaY = 1;
  116.         EraseRect( &(params->monitors->monitorList[gTheScreen].bounds) );
  117.         // set sliders
  118.         gMethod = METHOD;
  119.         gHvalue = H_VALUE;
  120.         gZoom = ZOOM;
  121.         // choose new colors
  122.         PickBrightRGB( &gColor1 );
  123.         PickBrightRGB( &gColor2 );
  124.     }
  125.     gEdge = gZoom;                // how many units whide?
  126.     gLeft = gTop = -( gZoom/2);    // left,top point is calc'd to make this centered
  127.  
  128.     width = params->monitors->monitorList[ gTheScreen ].bounds.right -
  129.              params->monitors->monitorList[ gTheScreen ].bounds.left;
  130.     
  131.     height = params->monitors->monitorList[ gTheScreen ].bounds.bottom -
  132.              params->monitors->monitorList[ gTheScreen ].bounds.top;
  133.     
  134.     // pick the smaller side ...
  135.     if (width > height)        windowEdge = height;
  136.     else                     windowEdge = width;
  137.  
  138.     gIncrement    = gEdge / gAmount;
  139.     gScale         = windowEdge / gEdge;
  140.  
  141.     gX0            = (width / 2) - ((gLeft + (gEdge / 2)) * gScale);
  142.     gY0            = (height / 2) - ((gTop  + (gEdge / 2)) * gScale);
  143.  
  144.  
  145. // color changes ?
  146.     if (HasColorQD() ) {
  147. // COLOR method #1 /////////////////////////////////////////////
  148.         if (gMethod == 1)         // outermost loop is gDeltaX
  149.             SetColorDiff( &rgbTheColor, &gColor1, &gColor2, 
  150.                 (double)gDeltaX / (double)gAmount );
  151.                 
  152. // COLOR method #2 /////////////////////////////////////////////
  153.         if (gMethod == 2)         // inner loop is gDeltaY
  154.             SetColorDiff( &rgbTheColor, &gColor1, &gColor2, 
  155.                 (double)gDeltaY / (double)gAmount );
  156.         RGBForeColor( &rgbTheColor);
  157.     }
  158.     
  159.     
  160.     
  161. // everytime we enter this DoDrawFrame() now, we're doing it
  162. // at each gDeltaY  (inner loop)
  163.  
  164.     // inner loop cycles from 1 to AMOUNT
  165.     if (gDeltaY++ > gAmount) {    // we're at the end of this loop?
  166.         gDeltaX++;                // increment the outside loop
  167.         gDeltaY = 1;            // we start back to 1
  168.     }
  169.     
  170.     // outer loop cycles from 1 to AMOUNT
  171.     if (gDeltaX > gAmount) {        // are we at the end of this loop?
  172.                                 // amended: we are done, for this one screen
  173. // so, time to move to the next screen
  174.         if (++gTheScreen >= params->monitors->monitorCount)
  175.             gTheScreen = 0;
  176.         
  177.         gDeltaX = gDeltaY = 1;
  178.         EraseRect( &(params->monitors->monitorList[gTheScreen].bounds) );
  179.         gMethod = METHOD; // just to be safe
  180.         PickBrightRGB( &gColor1 );
  181.         PickBrightRGB( &gColor2 );
  182.         return noErr;            // return out of here
  183.     }
  184.     
  185.     // we must have some drawing to do
  186.     x = gLeft + (gIncrement * gDeltaX);
  187.     y = gTop  + (gIncrement * gDeltaY);
  188.     
  189.  
  190.  
  191. // this is the main drawing loop //////////////////////////////////////////////////
  192.     for ( n = 1; n <= gAmount; ++n ) {
  193.         double theX, theY;
  194.         
  195. // COLOR method #3 /////////////////////////////////////////////
  196.         if (HasColorQD() && gMethod == 3) {    // innermost loop
  197.             SetColorDiff( &rgbTheColor, 
  198.                     &gColor1, &gColor2,  
  199.                         ( (double)n / (double)gAmount) );
  200.             RGBForeColor( &rgbTheColor);
  201.         }
  202. #if 0
  203.         xx = x - H * sin(y + tan(3 * y));
  204.         yy = y - H * sin(x + tan(3 * x));
  205. #else
  206.         xx = x - H_VALUE * sin(y + tan(3 * y));
  207.         yy = y - H_VALUE * sin(x + tan(3 * x));
  208. #endif
  209.         x = xx;
  210.         y = yy;
  211.         
  212. // we could be nice and check to ensure the plotted point is onscreen
  213. // (should we?) - I'll wait to hear from the multi-monitor folks (overlapped drawing?)
  214. // nope ... let us not wait ... check to be sure
  215.         theX = params->monitors->monitorList[ gTheScreen ].bounds.left +
  216.                 (gScale * x + gX0);
  217.         theY = params->monitors->monitorList[ gTheScreen ].bounds.top +
  218.                 (gScale * y + gY0);
  219. #if 1
  220.         if (theX >= params->monitors->monitorList[gTheScreen].bounds.left &&
  221.             theX <= params->monitors->monitorList[gTheScreen].bounds.right &&
  222.             theY >= params->monitors->monitorList[gTheScreen].bounds.top &&
  223.             theY <= params->monitors->monitorList[gTheScreen].bounds.bottom )
  224.         plot( theX, theY);
  225. #else
  226.         plot ( 
  227.             params->monitors->monitorList[ gTheScreen ].bounds.left +
  228.                 (gScale * x + gX0),
  229.             params->monitors->monitorList[ gTheScreen ].bounds.top +
  230.                 (gScale * y + gY0) );                    
  231. #endif
  232.  
  233.     } // for n
  234.  
  235.  
  236.     return noErr;
  237. }
  238.  
  239. //////////////////////////////////////////////////////////////////////////////////////
  240. // this is called when they click on something in the control panel
  241. OSErr 
  242. DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
  243.     // button got pushed?? 
  244.     return noErr;
  245. }
  246.  
  247.  
  248.  
  249. OSErr DoSelected(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
  250.     return noErr;
  251. }
  252.  
  253.  
  254.  
  255. OSErr DoAboutBox(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
  256.     return noErr;
  257. }
  258.  
  259.